home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-01-24 | 3.4 KB | 134 lines | [TEXT/AxoC] |
- LocalLanguage Pascal
- {-------------------------------------------------
- This document contains a unit conversion function.
-
- function cnvt (x, unit1, unit2) : Real
-
- • To load this function choose "Select All" under
- the "Edit" menu, then press "enter".
-
- For example,
-
- cnvt (10, inch, mm)
-
- returns 254 (i.e. 10 inches equals 254 mm).
-
- Units supported
- Length
- mm, cm, meter, km,
- inch, foot, yard, mile, furlong (fur), nautical mile (nMile)
-
- Speed
- km per hour (kmph), meters per second (mps),
- miles per hour (mph), nautical miles per hour (knot)
-
- Mass
- gram, kilogram (kg), tonne,
- ounce (oz), pound (lb), stone, ton
-
- Volume (Fluids)
- mililitre (ml), litre, megaLitre,
- fluid ounze (floz), pint (pt), US gallon (USgal or gal),
- British gallon (BrGal), acre foot (acreFt)
-
- Pressure
- kilopascal (kPa),
- pound per square inch (psi), atmosphere (atm)
-
- Temperature
- degrees centigrade (degC), degrees Kelvin (degK),
- degrees Farenheit (degF)
-
-
- • To add a unit to the list, declare it as a global
- array with 2 elements. The first element receives
- the conversion factor relative to a standard unit.
- For example, length units are defined relative to
- 1 meter and speed units relative to 1 meter per second.
- The second element receives the unit type.
- This is 1 for length units, 2 for speed units, etc.
- The unit type is used in "cnvt" for checking whether
- the requested conversion is a legal one.
- --------------------------------------------------}
-
- {• Global Declaration of supported units •}
- Var
- {• Length •}
- mm, cm, meter, km, inch, foot, yard, mile, fur, nauMile : Array[2]
- {• Speed •}
- mph, knot, kmph, mps : Array[2]
- {• Mass •}
- gram, kg, tonne, oz, lb, stone, ton : Array[2]
- {• Fluid volume •}
- ml, litre, megaLitre, floz, pt, gal, USGal, BrGal, acreFt : Array[2]
- {• Pressure •}
- kPa, psi, atm : Array[2]
- {• Temperature •}
- degC, degK, degF : Array[3]
-
- {• Conversion function •}
- function cnvt (x, unit1, unit2) : Real
- begin
- {• Perform conversion •}
- if unit1[2] = unit2[2] then
- begin
- if unit1[2] <> 6 then
- {• Normal conversion •}
- cnvt = x * unit1[1] / unit2[1]
- else
- {• Temperature conversion •}
- cnvt = (x + unit1[3]) * unit1[1] / unit2[1] - unit2[3]
- end
- else
- begin
- {• Different units •}
- write ('The two unit types are not compatible')
- cnvt = 0
- end
- end
-
- {• Set conversion factors •}
- mm[1] = 0.001; mm[2] = 1
- cm[1] = 0.01; cm[2] = 1
- meter[1] = 1; meter[2] = 1
- km[1] = 1000; km[2] = 1
- inch[1] = 0.0254; inch[2] = 1
- foot[1] = 0.305; foot[2] = 1
- yard[1] = 0.914; yard[2] = 1
- mile[1] = 1610; mile[2] = 1
- nauMile[1] = 1852; nauMile[2] = 1
- fur[1] = 201; fur[2] = 1
-
- mps[1] = 1; mps[2] = 2
- mph[1] = 0.44722; mph[2] = 2
- knot[1] = 0.51444; knot[2] = 2
- kmph[1] = 0.27778; kmph[2] = 2
-
- gram[1] = 1; gram[2] = 3
- kg[1] = 1000; kg[2] = 3
- tonne[1] = 1.0e6; tonne[2] = 3
- oz[1] = 28.3; oz[2] = 3
- lb[1] = 454; lb[2] = 3
- stone[1] = 6350; stone[2] = 3
- ton[1] = 1.02e6; ton[2] = 3
-
- litre[1] = 1; litre[2] = 4
- ml[1] = 0.01; ml[2] = 4
- megaLitre[1] = 1.0e6; megaLitre[2] = 4
- floz[1] = 0.0284; floz[2] = 4
- pt[1] = 0.568; pt[2] = 4
- gal[1] = 3.7853; gal[2] = 4
- USGal[1] = 3.7853; USGal[2] = 4
- BrGal[1] = 4.54596; BrGal[2] = 4
- acreFt[1] = 1.23e6; acreFt[2] = 4
-
- kPa[1] = 1; kPa[2] = 5
- psi[1] = 6.89; psi[2] = 5
- atm[1] = 101; atm[2] = 5
-
- degK[1] = 1; degK[2] = 6; degK[3] = 0
- degC[1] = 1; degC[2] = 6; degC[3] = 273.12
- degF[1] = 0.555556; degF[2] = 6; degF[3] = 459.61
-
-
-